#!/bin/bash

# Set the installation directory
INSTALL_DIR=~/MIRACL

# Clone the MIRACL repository
echo "Cloning MIRACL repository..."
git clone https://github.com/miracl/MIRACL.git "$INSTALL_DIR" || {
    echo "Failed to clone MIRACL repository. Exiting."
    exit 1
}

# Change directory to the cloned repository
cd "$INSTALL_DIR" || {
    echo "Failed to enter $INSTALL_DIR directory. Exiting."
    exit 1
}

# Build MIRACL
echo "Building MIRACL..."
make || {
    echo "Build failed. Exiting."
    exit 1
}

# Copy the library to /usr/local/lib
echo "Installing MIRACL library..."
sudo cp miracl.a /usr/local/lib/libmiracl.a || {
    echo "Failed to copy library to /usr/local/lib. Exiting."
    exit 1
}


echo "MIRACL installation completed successfully!"
